
local server_key = "SERVER:INFO"
local game_server_key = "SERVER:GAME_INFO";
local rv = 0;

local s_id = KEYS[1]
local gs_id = KEYS[2]

local o_n = ARGV[1]

-- redis.log(redis.LOG_WARNING, "data write " ..s_id, gs_id, o_n);

local s_info = redis.call('HGET', server_key, s_id);
-- redis.log(redis.LOG_WARNING, "data write " ..s_info);
if s_info ~= nil and type(s_info) ~= "boolean" then
    local _info = cjson.decode(s_info)
    _info.onlineNumber = _info.onlineNumber + o_n;
    redis.call('HSET', server_key, s_id, cjson.encode(_info))
else
      rv = -1
end

local gs_info = redis.call('HGET', game_server_key, gs_id);
if gs_info ~= nil and type(gs_info) ~= "boolean" then
    local _gs = cjson.decode(gs_info)
    _gs.onlineNumber = _gs.onlineNumber + o_n;
    redis.call('HSET', game_server_key, gs_id, cjson.encode(_gs))
else
      rv = rv + -2
end

return rv
